package a66weding.com.jiehuntong.adapter;

import android.content.Context;
import android.media.Image;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.andview.refreshview.recyclerview.BaseRecyclerAdapter;

import org.xutils.x;

import java.util.List;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.beans.CaseBean;
import a66weding.com.jiehuntong.beans.FriendsListBean;
import a66weding.com.jiehuntong.common.utils.ImageOptionsUtil;
import a66weding.com.jiehuntong.inner.OnItemClickLitener;

/**
 * Created by admin on 2016/8/2.
 */
public class CategoryAdapter_Case  extends BaseRecyclerAdapter<CategoryAdapter_Case.ViewHolder> {
    //如果有点击事件请设置一个监听;
    private OnItemClickLitener mOnItemClickLitener;

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener)
    {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    private Context context;
    private List<CaseBean.DataBean> data;
    public CategoryAdapter_Case(Context context,List<CaseBean.DataBean> data){
        this.context = context;
        this.data =data;
    }
    @Override
    public ViewHolder getViewHolder(View view) {
        return new ViewHolder(view);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType, boolean isItem) {
       View v =  LayoutInflater.from(context).inflate(R.layout.item_category_case,parent, false);
        ViewHolder holder = new ViewHolder(v);
        return holder;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position, boolean isItem) {
        if (mOnItemClickLitener!=null){
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemClick(holder.itemView,pos);
                }
            });
        }
        if (data.get(position)!=null){
            x.image().bind(holder.itme_case_attention,data.get(position).getNvc_Pic(), ImageOptionsUtil.getOptions292_700());
            if (data.get(position).getBusiness()!=null) {
                if (data.get(position).getBusiness().getNvc_Logo() != null) {
                    x.image().bind(holder.iv_homebus_markimg, data.get(position).getBusiness().getNvc_Logo(), ImageOptionsUtil.getOptions292_700());
                }
                holder.tv_homebusitem_hotalname.setText(data.get(position).getBusiness().getNvc_StoreName());
                holder.cate_homecustom_talk.setText(data.get(position).getNvc_Title());
                holder.cate_attention.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                    }
                });
            }
        }

    }

    @Override
    public int getAdapterItemCount() {
        if(data==null){
            return 0;
        }else{
            return data.size();
        }
    }

    public int getSize() {
        if(data==null) {
           return  0;
        }
        return data.size();
    }

    public  class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView itme_case_attention;
        private ImageView cate_attention;
        private ImageView iv_homebus_markimg;
        private TextView tv_homebusitem_hotalname;
        private TextView cate_homecustom_talk;
        public ViewHolder(View itemView) {
            super(itemView);
            itme_case_attention = (ImageView) itemView.findViewById(R.id.itme_case_attention);
            cate_attention = (ImageView) itemView.findViewById(R.id.cate_attention);
            iv_homebus_markimg = (ImageView) itemView.findViewById(R.id.iv_homebus_markimg);
            tv_homebusitem_hotalname = (TextView) itemView.findViewById(R.id.tv_homebusitem_hotalname);
            cate_homecustom_talk = (TextView) itemView.findViewById(R.id.cate_homecustom_talk);
        }
    }
    public void append(List<CaseBean.DataBean> data) {
        if (this.data != null) {
            this.data.addAll(data);
        } else {
            this.data = data;
        }
        notifyDataSetChanged();
    }
    public void clear() {
        if (data != null) {
            this.data.clear();
        }
    }

}
